// 执行消耗内存为 11780 kb 的范例
#include <stdio.h>
#include <stdbool.h> // true

int* twoSum(int* nums, int numsSize, int target, int* returnSize) {
    int hashtable[numsSize];
    int i = 0;
    int k = 0;
    int *ret = NULL;

#define HASH_IDX(val) abs((val)%numsSize)

    //初始化hash表
    for(;i<numsSize;i++){ 
        hashtable[i] = -1;
    }

    for(i=0;i<numsSize;i++){
        k = HASH_IDX(target - nums[i]);
        
        while(hashtable[k]!=-1) {
            if(nums[hashtable[k]] + nums[i] == target){ //防止冲突
                ret = (int*)malloc(sizeof(int)*2);
                ret[0] = hashtable[k];
                ret[1] = i;
                *returnSize=2;
                return ret;
            }
            k++;
            k = k%numsSize;
        }
       

        k = HASH_IDX(nums[i]);
		while(hashtable[k] != -1) { //hash冲突处理
			if(nums[hashtable[k]] == nums[i]) //值已经存过，则跳出
				break;
			k++;
			k = k % numsSize;
        }
        
        hashtable[k] = i;
    }
    *returnSize=0;
    return ret;
}

